let app = getApp();
const moment = require('../../../utils/moment.min.js')
const util = require('../../../utils/dateUtils.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user: null,
    roomList: [],
    tabActive: 0,
    tabsItem: [{
      name: '全部',
      status: '',
    },
    {
      name: '正在直播',
      status: 0,
    },
    {
      name: '直播预告',
      status: 1,
    },
    {
      name: '历史直播',
      status: 2,
    }
    ],
    liveStatus:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let _this = this;
    _this.setData({
      user: app.getUser(),
    })
    if (_this.data.user.id == null) return;
    _this.getLiveList();
  },
  getLiveList: function () {
    let that = this;
    app.requestUrl({
      method: 'GET',
      url: '/wxapi/zhibo/roomList',
      data: {
        centreId: that.data.user.centreId,
        liveStatus: that.data.liveStatus,
      },
      load: 1
    }).then((res) => {
      for (let key in res.data.data) {
        if (res.data.data[key].start_time)
          var startTime = '';
        startTime = res.data.data[key]['start_time'];
        res.data.data[key].start_time = util.formatTimeThree(startTime, "Y-M-D h:m:s");
        if (res.data.data[key].end_time)
          res.data.data[key].end_time = util.formatTimeThree(res.data.data[key]['end_time'], "Y-M-D h:m:s");
      };
      that.setData({
        roomList: res.data.data,
      });
    })
  },
  tabChange: function (event) {
    console.log(event);
    let that = this;
    if (event.detail.index == 0) {
      that.setData({
        liveStatus:''
      })
    }else if(event.detail.index == 1){
      that.setData({
        liveStatus:'101'
      })
    }else if(event.detail.index == 2){
      that.setData({
        liveStatus:'102'
      })
    }else if(event.detail.index == 3){
      that.setData({
        liveStatus:'103'
      })
    };
    that.getLiveList();
  }
})